//
// Created by Incredible on 17/3/15.
//

#ifndef INSERTIONSORT_SELECTIONSORT_H
#define INSERTIONSORT_SELECTIONSORT_H

#include <iostream>

/**
 * 选择排序
 *
 * @param arr
 * @param n
 */

template<typename T>
void selectionSort(T arr[], int n) {
    for (int i = 0; i < n; ++i) {

        //寻找[i, n)区间的最小值
        int minIndex = i;
        for (int j = i + 1; j < n; ++j) {
            if (arr[j] < arr[minIndex]) {
                minIndex = j;
            }
        }

        swap(arr[minIndex], arr[i]);
    }
}

#endif //INSERTIONSORT_SELECTIONSORT_H
